package com.example.wo.jsbapplication;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

public class NoteAdapter extends BaseAdapter {
    private List<Note> notes;
    private View myView;
    private TextView tvTitle,tvContent;
    private Context context;

    public NoteAdapter(Context context, List<Note> notes) {
        this.context=context;
        this.notes = notes;
    }


    public void setData(List<Note> data) {
        this.notes = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return notes.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Note note = notes.get(position);
        if (convertView==null){
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,parent,false);
        }
        tvTitle  = convertView.findViewById(R.id.tv_title);
        tvContent = convertView.findViewById(R.id.tv_content);
        tvTitle.setText(note.getTitle());
        tvContent.setText(note.getContent());
        return convertView;
    }
}
